{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "ecc18f12-db18-46c1-9bf4-7dc85d7c59c8",
   "metadata": {},
   "source": [
    "## Adding Web Search To Your LLM"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "2d90723f-17e9-4697-98e7-052f8613bf45",
   "metadata": {
    "height": 47
   },
   "outputs": [],
   "source": [
    "from dotenv import load_dotenv\n",
    "_ = load_dotenv()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "adf60829-5347-4e78-88ad-d720e4f370f0",
   "metadata": {},
   "source": [
    "#### Asking Your LLM For The Latest Information"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "051e1fb4-7730-4458-ad0b-c63eea7781e5",
   "metadata": {
    "height": 149
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'I\\'m sorry, but I don\\'t have any information about a specific \"R1\" thing that was announced by Rabbit. It\\'s possible that you may have misspoken or misunderstood the information you received. If you could provide more context or clarify your question, I would be happy to try and help you.'"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from utils import query_raven\n",
    "question = \"Hey, can you tell me more about this R1 thing that was announced by Rabbit? \"\n",
    "\n",
    "no_function_calling_prompt = \\\n",
    "f\"\"\"\n",
    "<s> [INST] {question} [/INST]\n",
    "\"\"\"\n",
    "query_raven(no_function_calling_prompt)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f1d2c1f5-78fc-4ee1-94f3-23e883f463ee",
   "metadata": {},
   "source": [
    "#### Providing Up To Date Information"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "1f6ca927-0e66-4db4-9746-961de1ef81d1",
   "metadata": {
    "height": 370
   },
   "outputs": [],
   "source": [
    "import os\n",
    "\n",
    "def do_web_search(full_user_prompt : str, num_results : int = 5):\n",
    "    API_URL = f'{os.getenv(\"DLAI_TAVILY_BASE_URL\", \"https://api.tavily.com\")}/search'\n",
    "    payload = \\\n",
    "    {\n",
    "      \"api_key\": os.environ[\"TAVILY_API_KEY\"],\n",
    "      \"query\": full_user_prompt,\n",
    "      \"search_depth\": \"basic\",\n",
    "      \"include_answer\": False,\n",
    "      \"include_images\": False,\n",
    "      \"include_raw_content\": False,\n",
    "      \"max_results\": num_results,\n",
    "      \"include_domains\": [],\n",
    "      \"exclude_domains\": []\n",
    "    }\n",
    "    import requests\n",
    "    response = requests.post(API_URL, json=payload)\n",
    "    response = response.json()\n",
    "    all_results = \"\\n\\n\".join(item[\"content\"] for item in response[\"results\"])\n",
    "    return all_results"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b54b8d1e-d084-4e22-8b42-a15510e4149d",
   "metadata": {},
   "source": [
    "#### Calling Raven"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "8910dd2e-ed87-4883-8508-48a4718ee5aa",
   "metadata": {
    "height": 285
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "do_web_search(full_user_prompt='R1 thing')\n"
     ]
    }
   ],
   "source": [
    "function_calling_prompt = \\\n",
    "\"\"\"\n",
    "Function:\n",
    "def do_web_search(full_user_prompt : str, num_results : int = 5):\n",
    "    '''\n",
    "    Searches the web for the user question.\n",
    "    '''\n",
    "\n",
    "Example:\n",
    "User Query: What is the oldest capital in the world?\n",
    "Call: do_web_search(full_user_prompt=\"oldest capital\")\n",
    "\n",
    "User Query: {query}<human_end>\n",
    "\"\"\"\n",
    "fc_result = query_raven(function_calling_prompt.format(query=question))\n",
    "print (fc_result)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "d25889b3-b7db-4144-aebd-b038717d4d1f",
   "metadata": {
    "height": 47
   },
   "outputs": [],
   "source": [
    "result = eval(fc_result)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "a13e640c-e6c3-4103-bd36-60f5ef87c39a",
   "metadata": {
    "height": 200
   },
   "outputs": [],
   "source": [
    "full_prompt = \\\n",
    "f\"\"\"\n",
    "<s> [INST]\n",
    "{result}\n",
    "\n",
    "Use the information above to answer the following question concisely.\n",
    "\n",
    "Question:\n",
    "{question} [/INST]\n",
    "\"\"\"\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "a0de0eab-230b-4951-896e-719e99740ec6",
   "metadata": {
    "height": 47
   },
   "outputs": [],
   "source": [
    "grounded_response = query_raven(full_prompt.format(question = question))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "57d01c0b-4327-4b96-b361-4bde9c34a266",
   "metadata": {
    "height": 30
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The R1 is an AI-powered gadget that can use your apps for you. It's a voice assistant that can answer questions, play music, and more. It's not a phone, but it can be used to control your apps. The R1 is powered by a custom-built natural-language operating system called rabbit OS. It's the first OS ever designed for voice assistants. The R1 is also connected to Perplexity, an AI search engine, so it can deliver more or less real-time information about news, sports scores, and more. The R1 is not a phone, but it can be used to control your apps. The R1 is a voice assistant that can use your apps for you.\n"
     ]
    }
   ],
   "source": [
    "print (grounded_response)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a01059e6-4f7e-4158-9411-c5241888d90f",
   "metadata": {},
   "source": [
    "## Chatting With Your SQL Database\n",
    "> Note below: The database values are randomly generated so your values may differ from those in the video.\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "1d4498e7-2321-4217-9b5d-676e66123d37",
   "metadata": {
    "height": 47
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Toys in database:\n",
      "(1, 'Mighty Doll', 6.25)\n",
      "(2, 'Crazy Bear', 13.25)\n",
      "(3, 'Magic Robot', 19.4)\n",
      "(4, 'Wonder Car', 15.14)\n",
      "(5, 'Super Bear', 19.01)\n",
      "(6, 'Wonder Bear', 15.8)\n",
      "(7, 'Super Doll', 8.78)\n",
      "(8, 'Super Robot', 18.72)\n",
      "(9, 'Wonder Car', 6.85)\n",
      "(10, 'Happy Car', 11.09)\n",
      "(11, 'Mighty Doll', 5.38)\n",
      "(12, 'Magic Dragon', 16.52)\n",
      "(13, 'Wonder Car', 7.81)\n",
      "(14, 'Mighty Doll', 7.63)\n",
      "(15, 'Happy Car', 14.53)\n",
      "(16, 'Happy Car', 6.08)\n",
      "(17, 'Crazy Doll', 7.29)\n",
      "(18, 'Super Bear', 7.9)\n",
      "(19, 'Happy Bear', 12.83)\n",
      "(20, 'Crazy Car', 9.16)\n",
      "(21, 'Mighty Robot', 7.72)\n",
      "(22, 'Crazy Car', 13.77)\n",
      "(23, 'Wonder Train', 11.39)\n",
      "(24, 'Wonder Car', 19.0)\n",
      "(25, 'Wonder Bear', 9.78)\n",
      "(26, 'Mighty Doll', 13.8)\n",
      "(27, 'Crazy Robot', 19.86)\n",
      "(28, 'Super Train', 5.96)\n",
      "(29, 'Mighty Bear', 7.9)\n",
      "(30, 'Magic Bear', 9.6)\n",
      "(31, 'Mighty Car', 5.8)\n",
      "(32, 'Super Bear', 8.75)\n",
      "(33, 'Super Robot', 15.95)\n",
      "(34, 'Magic Car', 12.71)\n",
      "(35, 'Crazy Robot', 19.4)\n",
      "(36, 'Crazy Train', 19.25)\n",
      "(37, 'Crazy Train', 8.37)\n",
      "(38, 'Happy Car', 11.37)\n",
      "(39, 'Crazy Robot', 18.27)\n",
      "(40, 'Wonder Train', 7.81)\n",
      "(41, 'Magic Bear', 10.19)\n",
      "(42, 'Crazy Car', 7.74)\n",
      "(43, 'Wonder Car', 18.46)\n",
      "(44, 'Crazy Car', 7.5)\n",
      "(45, 'Mighty Robot', 13.44)\n",
      "(46, 'Wonder Bear', 16.91)\n",
      "(47, 'Magic Dragon', 12.26)\n",
      "(48, 'Wonder Train', 5.49)\n",
      "(49, 'Mighty Robot', 5.53)\n",
      "(50, 'Happy Robot', 19.91)\n",
      "(51, 'Wonder Robot', 5.7)\n",
      "(52, 'Magic Doll', 18.85)\n",
      "(53, 'Super Car', 13.69)\n",
      "(54, 'Happy Robot', 11.18)\n",
      "(55, 'Wonder Bear', 8.7)\n",
      "(56, 'Wonder Dragon', 13.87)\n",
      "(57, 'Super Dragon', 7.0)\n",
      "(58, 'Wonder Dragon', 10.54)\n",
      "(59, 'Wonder Dragon', 17.91)\n",
      "(60, 'Happy Car', 10.04)\n",
      "(61, 'Super Dragon', 7.96)\n",
      "(62, 'Crazy Car', 9.13)\n",
      "(63, 'Happy Robot', 5.84)\n",
      "(64, 'Crazy Doll', 9.11)\n",
      "(65, 'Wonder Bear', 13.47)\n",
      "(66, 'Crazy Train', 11.81)\n",
      "(67, 'Happy Doll', 18.3)\n",
      "(68, 'Magic Dragon', 18.62)\n",
      "(69, 'Mighty Train', 13.28)\n",
      "(70, 'Mighty Bear', 15.7)\n",
      "(71, 'Happy Doll', 9.58)\n",
      "(72, 'Happy Bear', 12.97)\n",
      "(73, 'Wonder Doll', 8.43)\n",
      "(74, 'Super Train', 19.92)\n",
      "(75, 'Mighty Train', 13.58)\n",
      "(76, 'Happy Doll', 9.72)\n",
      "(77, 'Magic Car', 6.27)\n",
      "(78, 'Magic Doll', 15.95)\n",
      "(79, 'Super Train', 10.45)\n",
      "(80, 'Super Train', 5.62)\n",
      "(81, 'Super Bear', 14.2)\n",
      "(82, 'Magic Dragon', 13.48)\n",
      "(83, 'Magic Dragon', 7.89)\n",
      "(84, 'Magic Bear', 11.51)\n",
      "(85, 'Crazy Robot', 14.92)\n",
      "(86, 'Happy Doll', 10.63)\n",
      "(87, 'Wonder Bear', 5.38)\n",
      "(88, 'Happy Car', 15.47)\n",
      "(89, 'Wonder Car', 16.5)\n",
      "(90, 'Crazy Robot', 8.26)\n",
      "(91, 'Super Bear', 17.54)\n",
      "(92, 'Crazy Car', 5.97)\n",
      "(93, 'Wonder Car', 13.73)\n",
      "(94, 'Mighty Bear', 7.18)\n",
      "(95, 'Crazy Car', 14.18)\n",
      "(96, 'Super Dragon', 16.77)\n",
      "(97, 'Wonder Bear', 6.37)\n",
      "(98, 'Crazy Car', 14.0)\n",
      "(99, 'Mighty Car', 12.76)\n",
      "(100, 'Super Train', 5.53)\n",
      "(101, 'Wonder Train', 5.78)\n",
      "(102, 'Mighty Doll', 7.53)\n",
      "(103, 'Wonder Doll', 12.19)\n",
      "(104, 'Magic Doll', 6.8)\n",
      "(105, 'Magic Train', 17.67)\n",
      "(106, 'Super Dragon', 13.49)\n",
      "(107, 'Wonder Train', 19.25)\n",
      "(108, 'Happy Train', 15.74)\n",
      "(109, 'Wonder Dragon', 5.89)\n",
      "(110, 'Happy Bear', 17.7)\n",
      "(111, 'Wonder Doll', 9.32)\n",
      "(112, 'Crazy Car', 8.75)\n",
      "(113, 'Super Train', 17.85)\n",
      "(114, 'Super Dragon', 17.68)\n",
      "(115, 'Magic Car', 18.87)\n",
      "(116, 'Mighty Dragon', 13.11)\n",
      "(117, 'Wonder Doll', 8.43)\n",
      "(118, 'Magic Train', 12.87)\n",
      "(119, 'Super Robot', 8.28)\n",
      "(120, 'Magic Bear', 10.42)\n",
      "(121, 'Crazy Dragon', 18.93)\n",
      "(122, 'Super Bear', 8.0)\n",
      "(123, 'Magic Train', 18.42)\n",
      "(124, 'Wonder Car', 17.26)\n",
      "(125, 'Wonder Train', 19.56)\n",
      "(126, 'Wonder Car', 10.46)\n",
      "(127, 'Mighty Dragon', 16.01)\n",
      "(128, 'Happy Train', 10.52)\n",
      "(129, 'Wonder Dragon', 10.62)\n",
      "(130, 'Magic Car', 6.67)\n",
      "(131, 'Happy Dragon', 15.48)\n",
      "(132, 'Crazy Car', 12.71)\n",
      "(133, 'Happy Bear', 19.65)\n",
      "(134, 'Happy Dragon', 11.97)\n",
      "(135, 'Happy Robot', 19.69)\n",
      "(136, 'Mighty Car', 18.93)\n",
      "(137, 'Super Robot', 14.04)\n",
      "(138, 'Wonder Doll', 7.34)\n",
      "(139, 'Wonder Train', 16.13)\n",
      "(140, 'Mighty Bear', 10.0)\n",
      "(141, 'Super Train', 15.42)\n",
      "(142, 'Happy Doll', 12.39)\n",
      "(143, 'Mighty Train', 14.37)\n",
      "(144, 'Crazy Doll', 9.55)\n",
      "(145, 'Mighty Train', 9.95)\n",
      "(146, 'Mighty Train', 16.39)\n",
      "(147, 'Magic Car', 16.25)\n",
      "(148, 'Crazy Car', 18.94)\n",
      "(149, 'Crazy Train', 19.84)\n",
      "(150, 'Happy Train', 18.49)\n",
      "(151, 'Crazy Doll', 19.23)\n",
      "(152, 'Crazy Robot', 7.22)\n",
      "(153, 'Super Robot', 9.27)\n",
      "(154, 'Super Bear', 8.7)\n",
      "(155, 'Magic Doll', 18.75)\n",
      "(156, 'Magic Robot', 19.37)\n",
      "(157, 'Happy Doll', 7.03)\n",
      "(158, 'Super Robot', 6.63)\n",
      "(159, 'Magic Car', 12.94)\n",
      "(160, 'Mighty Dragon', 8.21)\n",
      "(161, 'Mighty Robot', 5.64)\n",
      "(162, 'Super Train', 13.9)\n",
      "(163, 'Wonder Robot', 13.91)\n",
      "(164, 'Crazy Doll', 13.78)\n",
      "(165, 'Happy Bear', 11.87)\n",
      "(166, 'Mighty Train', 12.79)\n",
      "(167, 'Happy Doll', 17.85)\n",
      "(168, 'Crazy Train', 14.72)\n",
      "(169, 'Mighty Bear', 8.97)\n",
      "(170, 'Magic Bear', 6.76)\n",
      "(171, 'Magic Bear', 15.78)\n",
      "(172, 'Super Robot', 14.21)\n",
      "(173, 'Magic Doll', 5.03)\n",
      "(174, 'Mighty Robot', 18.13)\n",
      "(175, 'Super Bear', 5.27)\n",
      "(176, 'Super Train', 8.84)\n",
      "(177, 'Wonder Train', 10.28)\n",
      "(178, 'Super Doll', 10.32)\n",
      "(179, 'Happy Car', 14.27)\n",
      "(180, 'Happy Train', 6.46)\n",
      "(181, 'Crazy Robot', 13.58)\n",
      "(182, 'Wonder Dragon', 16.66)\n",
      "(183, 'Super Robot', 11.53)\n",
      "(184, 'Super Doll', 11.9)\n",
      "(185, 'Super Train', 15.34)\n",
      "(186, 'Mighty Robot', 16.18)\n",
      "(187, 'Magic Bear', 14.76)\n",
      "(188, 'Super Dragon', 17.32)\n",
      "(189, 'Wonder Bear', 10.26)\n",
      "(190, 'Mighty Doll', 5.71)\n",
      "(191, 'Mighty Dragon', 13.01)\n",
      "(192, 'Magic Robot', 13.78)\n",
      "(193, 'Happy Robot', 15.3)\n",
      "(194, 'Super Car', 8.5)\n",
      "(195, 'Wonder Bear', 5.26)\n",
      "(196, 'Super Robot', 11.63)\n",
      "(197, 'Crazy Robot', 8.45)\n",
      "(198, 'Super Car', 9.89)\n",
      "(199, 'Mighty Dragon', 17.04)\n",
      "(200, 'Wonder Bear', 12.1)\n",
      "(201, 'Wonder Train', 11.26)\n",
      "(202, 'Wonder Dragon', 15.73)\n",
      "(203, 'Super Dragon', 5.13)\n",
      "(204, 'Wonder Car', 8.65)\n",
      "(205, 'Mighty Bear', 16.64)\n",
      "(206, 'Super Robot', 8.86)\n",
      "(207, 'Crazy Doll', 12.86)\n",
      "(208, 'Magic Car', 19.88)\n",
      "(209, 'Crazy Bear', 11.3)\n",
      "(210, 'Wonder Train', 16.26)\n",
      "(211, 'Wonder Robot', 15.37)\n",
      "(212, 'Happy Train', 7.43)\n",
      "(213, 'Happy Robot', 5.35)\n",
      "(214, 'Super Train', 15.33)\n",
      "(215, 'Magic Doll', 5.51)\n",
      "(216, 'Mighty Car', 12.56)\n",
      "(217, 'Magic Car', 16.31)\n",
      "(218, 'Wonder Robot', 6.41)\n",
      "(219, 'Wonder Dragon', 9.56)\n",
      "(220, 'Mighty Car', 19.68)\n",
      "(221, 'Mighty Car', 5.77)\n",
      "(222, 'Wonder Robot', 14.23)\n",
      "(223, 'Happy Bear', 7.1)\n",
      "(224, 'Magic Car', 6.74)\n",
      "(225, 'Wonder Train', 6.42)\n",
      "(226, 'Happy Car', 7.12)\n",
      "(227, 'Crazy Car', 15.95)\n",
      "(228, 'Crazy Train', 13.47)\n",
      "(229, 'Wonder Car', 6.26)\n",
      "(230, 'Crazy Dragon', 17.87)\n",
      "(231, 'Magic Dragon', 7.92)\n",
      "(232, 'Happy Bear', 16.95)\n",
      "(233, 'Happy Dragon', 16.09)\n",
      "(234, 'Magic Bear', 7.89)\n",
      "(235, 'Mighty Car', 16.7)\n",
      "(236, 'Magic Bear', 14.47)\n",
      "(237, 'Wonder Car', 7.8)\n",
      "(238, 'Super Train', 10.75)\n",
      "(239, 'Magic Bear', 7.3)\n",
      "(240, 'Wonder Train', 10.74)\n",
      "(241, 'Super Doll', 14.02)\n",
      "(242, 'Super Bear', 18.5)\n",
      "(243, 'Happy Doll', 8.78)\n",
      "(244, 'Super Bear', 11.93)\n",
      "(245, 'Mighty Car', 17.84)\n",
      "(246, 'Mighty Bear', 9.39)\n",
      "(247, 'Crazy Robot', 19.4)\n",
      "(248, 'Crazy Train', 6.03)\n",
      "(249, 'Magic Doll', 6.74)\n",
      "(250, 'Magic Bear', 18.44)\n",
      "(251, 'Wonder Doll', 11.73)\n",
      "(252, 'Crazy Robot', 15.23)\n",
      "(253, 'Wonder Car', 9.65)\n",
      "(254, 'Mighty Bear', 16.84)\n",
      "(255, 'Wonder Robot', 5.94)\n",
      "(256, 'Super Car', 15.14)\n",
      "(257, 'Magic Bear', 7.92)\n",
      "(258, 'Mighty Train', 6.98)\n",
      "(259, 'Wonder Doll', 15.0)\n",
      "(260, 'Super Robot', 7.04)\n",
      "(261, 'Wonder Robot', 9.8)\n",
      "(262, 'Wonder Train', 16.61)\n",
      "(263, 'Happy Bear', 8.55)\n",
      "(264, 'Magic Doll', 7.31)\n",
      "(265, 'Mighty Bear', 5.99)\n",
      "(266, 'Crazy Robot', 19.26)\n",
      "(267, 'Happy Train', 7.29)\n",
      "(268, 'Mighty Doll', 17.51)\n",
      "(269, 'Mighty Dragon', 16.62)\n",
      "(270, 'Super Car', 12.98)\n",
      "(271, 'Wonder Car', 17.63)\n",
      "(272, 'Happy Bear', 10.4)\n",
      "(273, 'Crazy Bear', 15.89)\n",
      "(274, 'Super Train', 8.94)\n",
      "(275, 'Magic Robot', 5.47)\n",
      "(276, 'Super Robot', 8.4)\n",
      "(277, 'Happy Robot', 16.9)\n",
      "(278, 'Mighty Train', 15.69)\n",
      "(279, 'Mighty Car', 19.63)\n",
      "(280, 'Magic Bear', 11.95)\n",
      "(281, 'Crazy Train', 19.07)\n",
      "(282, 'Magic Dragon', 7.53)\n",
      "(283, 'Crazy Robot', 13.66)\n",
      "(284, 'Crazy Train', 15.58)\n",
      "(285, 'Super Car', 5.08)\n",
      "(286, 'Wonder Robot', 13.74)\n",
      "(287, 'Super Doll', 18.43)\n",
      "(288, 'Magic Bear', 6.96)\n",
      "(289, 'Happy Robot', 8.08)\n",
      "(290, 'Happy Dragon', 6.7)\n",
      "(291, 'Wonder Doll', 9.61)\n",
      "(292, 'Super Dragon', 15.99)\n",
      "(293, 'Happy Robot', 9.31)\n",
      "(294, 'Super Bear', 10.27)\n",
      "(295, 'Mighty Train', 15.33)\n",
      "(296, 'Mighty Train', 9.75)\n",
      "(297, 'Crazy Car', 19.4)\n",
      "(298, 'Super Bear', 13.6)\n",
      "(299, 'Super Train', 11.79)\n",
      "(300, 'Mighty Dragon', 15.05)\n",
      "(301, 'Crazy Train', 18.43)\n",
      "(302, 'Crazy Car', 7.56)\n",
      "(303, 'Magic Car', 13.83)\n",
      "(304, 'Super Doll', 12.33)\n",
      "(305, 'Mighty Car', 7.03)\n",
      "(306, 'Magic Dragon', 11.6)\n",
      "(307, 'Super Doll', 10.44)\n",
      "(308, 'Super Train', 9.8)\n",
      "(309, 'Mighty Train', 14.85)\n",
      "(310, 'Magic Dragon', 15.32)\n",
      "(311, 'Magic Robot', 6.56)\n",
      "(312, 'Crazy Doll', 10.18)\n",
      "(313, 'Super Train', 6.94)\n",
      "(314, 'Crazy Train', 14.19)\n",
      "(315, 'Magic Bear', 18.35)\n",
      "(316, 'Happy Train', 12.97)\n",
      "(317, 'Crazy Doll', 8.88)\n",
      "(318, 'Mighty Bear', 8.51)\n",
      "(319, 'Mighty Train', 17.48)\n",
      "(320, 'Happy Robot', 17.92)\n",
      "(321, 'Wonder Car', 10.36)\n",
      "(322, 'Mighty Train', 19.82)\n",
      "(323, 'Super Doll', 7.07)\n",
      "(324, 'Happy Robot', 6.95)\n",
      "(325, 'Crazy Train', 7.01)\n",
      "(326, 'Magic Dragon', 6.67)\n",
      "(327, 'Crazy Dragon', 5.66)\n",
      "(328, 'Crazy Dragon', 14.98)\n",
      "(329, 'Super Dragon', 10.31)\n",
      "(330, 'Magic Bear', 7.2)\n",
      "(331, 'Happy Car', 17.91)\n",
      "(332, 'Crazy Dragon', 9.36)\n",
      "(333, 'Wonder Dragon', 8.37)\n",
      "(334, 'Wonder Train', 6.27)\n",
      "(335, 'Mighty Robot', 6.92)\n",
      "(336, 'Happy Bear', 8.19)\n",
      "(337, 'Wonder Doll', 18.36)\n",
      "(338, 'Mighty Dragon', 15.89)\n",
      "(339, 'Happy Robot', 17.34)\n",
      "(340, 'Wonder Robot', 14.74)\n",
      "(341, 'Super Train', 16.04)\n",
      "(342, 'Wonder Dragon', 12.09)\n",
      "(343, 'Happy Doll', 12.01)\n",
      "(344, 'Crazy Doll', 11.73)\n",
      "(345, 'Magic Bear', 5.46)\n",
      "(346, 'Crazy Bear', 6.77)\n",
      "(347, 'Super Train', 6.65)\n",
      "(348, 'Happy Bear', 17.59)\n",
      "(349, 'Mighty Robot', 17.76)\n",
      "(350, 'Wonder Train', 7.14)\n",
      "(351, 'Happy Bear', 13.61)\n",
      "(352, 'Super Bear', 15.39)\n",
      "(353, 'Super Dragon', 7.82)\n",
      "(354, 'Super Car', 19.29)\n",
      "(355, 'Super Car', 19.84)\n",
      "(356, 'Mighty Car', 11.74)\n",
      "(357, 'Crazy Car', 12.03)\n",
      "(358, 'Wonder Car', 16.27)\n",
      "(359, 'Wonder Dragon', 18.37)\n",
      "(360, 'Happy Doll', 5.97)\n",
      "(361, 'Happy Robot', 6.83)\n",
      "(362, 'Magic Train', 11.31)\n",
      "(363, 'Mighty Dragon', 12.95)\n",
      "(364, 'Mighty Robot', 14.82)\n",
      "(365, 'Happy Train', 6.32)\n",
      "(366, 'Super Doll', 5.15)\n",
      "(367, 'Magic Doll', 5.47)\n",
      "(368, 'Wonder Car', 11.3)\n",
      "(369, 'Happy Bear', 8.71)\n",
      "(370, 'Mighty Bear', 9.8)\n",
      "(371, 'Super Bear', 13.5)\n",
      "(372, 'Super Bear', 16.52)\n",
      "(373, 'Mighty Bear', 11.32)\n",
      "(374, 'Super Bear', 6.98)\n",
      "(375, 'Super Train', 17.9)\n",
      "(376, 'Crazy Dragon', 8.3)\n",
      "(377, 'Crazy Robot', 14.19)\n",
      "(378, 'Happy Dragon', 19.25)\n",
      "(379, 'Magic Robot', 17.84)\n",
      "(380, 'Crazy Dragon', 12.64)\n",
      "(381, 'Wonder Train', 13.32)\n",
      "(382, 'Happy Car', 15.07)\n",
      "(383, 'Magic Doll', 16.4)\n",
      "(384, 'Super Train', 12.15)\n",
      "(385, 'Magic Dragon', 9.3)\n",
      "(386, 'Crazy Bear', 10.09)\n",
      "(387, 'Mighty Dragon', 15.43)\n",
      "(388, 'Super Car', 7.7)\n",
      "(389, 'Mighty Dragon', 12.42)\n",
      "(390, 'Mighty Train', 10.36)\n",
      "(391, 'Magic Doll', 16.91)\n",
      "(392, 'Wonder Train', 6.44)\n",
      "(393, 'Magic Doll', 8.73)\n",
      "(394, 'Wonder Car', 5.45)\n",
      "(395, 'Happy Bear', 9.94)\n",
      "(396, 'Mighty Train', 15.69)\n",
      "(397, 'Super Doll', 9.41)\n",
      "(398, 'Mighty Bear', 19.33)\n",
      "(399, 'Mighty Dragon', 19.33)\n",
      "(400, 'Wonder Car', 9.11)\n",
      "(401, 'Happy Doll', 9.65)\n",
      "(402, 'Happy Doll', 11.55)\n",
      "(403, 'Magic Car', 13.99)\n",
      "(404, 'Wonder Bear', 5.36)\n",
      "(405, 'Crazy Bear', 9.43)\n",
      "(406, 'Super Doll', 13.19)\n",
      "(407, 'Crazy Car', 13.17)\n",
      "(408, 'Happy Doll', 10.79)\n",
      "(409, 'Super Doll', 5.65)\n",
      "(410, 'Mighty Doll', 14.97)\n",
      "(411, 'Wonder Dragon', 7.14)\n",
      "(412, 'Wonder Robot', 19.83)\n",
      "(413, 'Super Bear', 16.7)\n",
      "(414, 'Happy Dragon', 11.34)\n",
      "(415, 'Magic Doll', 15.48)\n",
      "(416, 'Happy Dragon', 10.15)\n",
      "(417, 'Mighty Car', 12.27)\n",
      "(418, 'Magic Robot', 9.74)\n",
      "(419, 'Super Robot', 9.69)\n",
      "(420, 'Wonder Dragon', 12.74)\n",
      "(421, 'Wonder Robot', 8.99)\n",
      "(422, 'Mighty Car', 19.67)\n",
      "(423, 'Mighty Car', 9.13)\n",
      "(424, 'Happy Train', 8.87)\n",
      "(425, 'Mighty Train', 12.29)\n",
      "(426, 'Happy Dragon', 5.73)\n",
      "(427, 'Crazy Train', 5.44)\n",
      "(428, 'Happy Car', 5.83)\n",
      "(429, 'Super Doll', 11.15)\n",
      "(430, 'Mighty Doll', 8.27)\n",
      "(431, 'Wonder Dragon', 8.3)\n",
      "(432, 'Wonder Train', 5.93)\n",
      "(433, 'Super Bear', 10.45)\n",
      "(434, 'Mighty Dragon', 6.53)\n",
      "(435, 'Crazy Robot', 19.29)\n",
      "(436, 'Mighty Car', 13.87)\n",
      "(437, 'Happy Car', 16.62)\n",
      "(438, 'Mighty Train', 7.94)\n",
      "(439, 'Wonder Train', 6.92)\n",
      "(440, 'Crazy Train', 9.67)\n",
      "(441, 'Wonder Doll', 13.09)\n",
      "(442, 'Happy Dragon', 6.91)\n",
      "(443, 'Super Doll', 19.05)\n",
      "(444, 'Crazy Dragon', 13.43)\n",
      "(445, 'Mighty Train', 8.86)\n",
      "(446, 'Crazy Car', 10.14)\n",
      "(447, 'Super Doll', 12.35)\n",
      "(448, 'Happy Car', 9.8)\n",
      "(449, 'Super Robot', 14.37)\n",
      "(450, 'Super Train', 13.05)\n",
      "(451, 'Wonder Train', 5.68)\n",
      "(452, 'Crazy Doll', 17.98)\n",
      "(453, 'Super Robot', 5.38)\n",
      "(454, 'Wonder Bear', 11.42)\n",
      "(455, 'Wonder Doll', 12.3)\n",
      "(456, 'Wonder Bear', 11.55)\n",
      "(457, 'Magic Bear', 8.79)\n",
      "(458, 'Wonder Train', 13.81)\n",
      "(459, 'Happy Bear', 11.73)\n",
      "(460, 'Mighty Robot', 19.44)\n",
      "(461, 'Mighty Robot', 6.99)\n",
      "(462, 'Magic Dragon', 14.21)\n",
      "(463, 'Mighty Doll', 7.82)\n",
      "(464, 'Wonder Dragon', 19.3)\n",
      "(465, 'Crazy Robot', 17.6)\n",
      "(466, 'Happy Dragon', 5.59)\n",
      "(467, 'Crazy Doll', 13.78)\n",
      "(468, 'Happy Doll', 7.87)\n",
      "(469, 'Crazy Bear', 7.65)\n",
      "(470, 'Crazy Dragon', 7.08)\n",
      "(471, 'Wonder Train', 5.59)\n",
      "(472, 'Crazy Robot', 12.15)\n",
      "(473, 'Wonder Train', 10.34)\n",
      "(474, 'Magic Train', 18.58)\n",
      "(475, 'Crazy Doll', 18.83)\n",
      "(476, 'Crazy Car', 5.43)\n",
      "(477, 'Wonder Dragon', 15.15)\n",
      "(478, 'Happy Doll', 16.17)\n",
      "(479, 'Happy Bear', 6.42)\n",
      "(480, 'Happy Dragon', 9.46)\n",
      "(481, 'Super Car', 19.69)\n",
      "(482, 'Mighty Bear', 9.29)\n",
      "(483, 'Mighty Train', 16.41)\n",
      "(484, 'Magic Train', 13.38)\n",
      "(485, 'Happy Dragon', 11.57)\n",
      "(486, 'Crazy Doll', 9.18)\n",
      "(487, 'Super Car', 9.66)\n",
      "(488, 'Magic Car', 9.78)\n",
      "(489, 'Super Robot', 7.4)\n",
      "(490, 'Magic Train', 10.11)\n",
      "(491, 'Mighty Bear', 9.19)\n",
      "(492, 'Crazy Train', 7.39)\n",
      "(493, 'Magic Train', 9.46)\n",
      "(494, 'Wonder Bear', 10.15)\n",
      "(495, 'Wonder Bear', 11.54)\n",
      "(496, 'Happy Car', 13.46)\n",
      "(497, 'Magic Dragon', 13.49)\n",
      "(498, 'Crazy Dragon', 18.69)\n",
      "(499, 'Mighty Doll', 8.77)\n",
      "(500, 'Crazy Car', 14.01)\n",
      "(501, 'Wonder Train', 8.08)\n",
      "(502, 'Mighty Train', 5.42)\n",
      "(503, 'Crazy Car', 14.15)\n",
      "(504, 'Mighty Robot', 14.23)\n",
      "(505, 'Happy Robot', 6.07)\n",
      "(506, 'Super Train', 5.8)\n",
      "(507, 'Mighty Car', 7.44)\n",
      "(508, 'Wonder Robot', 8.82)\n",
      "(509, 'Wonder Car', 16.6)\n",
      "(510, 'Mighty Car', 8.44)\n",
      "(511, 'Wonder Train', 15.81)\n",
      "(512, 'Super Dragon', 15.54)\n",
      "(513, 'Crazy Dragon', 16.37)\n",
      "(514, 'Happy Robot', 7.24)\n",
      "(515, 'Wonder Bear', 10.66)\n",
      "(516, 'Crazy Dragon', 17.08)\n",
      "(517, 'Magic Train', 16.85)\n",
      "(518, 'Wonder Train', 8.36)\n",
      "(519, 'Magic Robot', 14.17)\n",
      "(520, 'Happy Dragon', 10.02)\n",
      "(521, 'Magic Car', 15.88)\n",
      "(522, 'Happy Dragon', 17.27)\n",
      "(523, 'Crazy Doll', 5.29)\n",
      "(524, 'Mighty Car', 14.67)\n",
      "(525, 'Super Dragon', 17.54)\n",
      "(526, 'Crazy Robot', 10.73)\n",
      "(527, 'Wonder Robot', 14.21)\n",
      "(528, 'Happy Train', 17.11)\n",
      "(529, 'Wonder Train', 13.28)\n",
      "(530, 'Crazy Bear', 7.83)\n",
      "(531, 'Super Robot', 17.63)\n",
      "(532, 'Magic Bear', 18.66)\n",
      "(533, 'Mighty Robot', 15.78)\n",
      "(534, 'Wonder Car', 12.32)\n",
      "(535, 'Magic Robot', 18.88)\n",
      "(536, 'Mighty Dragon', 8.29)\n",
      "(537, 'Crazy Car', 18.27)\n",
      "(538, 'Super Doll', 14.01)\n",
      "(539, 'Happy Train', 11.18)\n",
      "(540, 'Crazy Train', 17.65)\n",
      "(541, 'Mighty Train', 5.9)\n",
      "(542, 'Wonder Doll', 10.46)\n",
      "(543, 'Super Dragon', 6.87)\n",
      "(544, 'Wonder Dragon', 14.48)\n",
      "(545, 'Super Doll', 5.97)\n",
      "(546, 'Crazy Train', 19.69)\n",
      "(547, 'Crazy Bear', 12.77)\n",
      "(548, 'Wonder Train', 18.07)\n",
      "(549, 'Crazy Train', 11.68)\n",
      "(550, 'Magic Car', 7.78)\n",
      "(551, 'Super Doll', 13.68)\n",
      "(552, 'Mighty Dragon', 8.49)\n",
      "(553, 'Wonder Train', 19.11)\n",
      "(554, 'Mighty Robot', 7.07)\n",
      "(555, 'Crazy Train', 16.51)\n",
      "(556, 'Wonder Car', 14.45)\n",
      "(557, 'Magic Robot', 12.06)\n",
      "(558, 'Crazy Robot', 8.52)\n",
      "(559, 'Super Robot', 11.79)\n",
      "(560, 'Happy Train', 15.52)\n",
      "(561, 'Super Doll', 18.64)\n",
      "(562, 'Wonder Dragon', 14.81)\n",
      "(563, 'Magic Robot', 18.89)\n",
      "(564, 'Happy Train', 14.3)\n",
      "(565, 'Wonder Train', 13.3)\n",
      "(566, 'Wonder Car', 15.57)\n",
      "(567, 'Wonder Car', 14.99)\n",
      "(568, 'Mighty Car', 15.14)\n",
      "(569, 'Super Train', 17.97)\n",
      "(570, 'Wonder Dragon', 7.38)\n",
      "(571, 'Happy Train', 11.9)\n",
      "(572, 'Wonder Doll', 10.34)\n",
      "(573, 'Super Dragon', 16.63)\n",
      "(574, 'Wonder Car', 17.55)\n",
      "(575, 'Happy Bear', 8.53)\n",
      "(576, 'Magic Doll', 6.49)\n",
      "(577, 'Magic Robot', 12.69)\n",
      "(578, 'Super Train', 9.08)\n",
      "(579, 'Mighty Train', 15.32)\n",
      "(580, 'Super Dragon', 11.76)\n",
      "(581, 'Crazy Car', 5.77)\n",
      "(582, 'Magic Bear', 6.43)\n",
      "(583, 'Crazy Robot', 6.6)\n",
      "(584, 'Mighty Bear', 10.05)\n",
      "(585, 'Wonder Dragon', 6.16)\n",
      "(586, 'Super Train', 10.94)\n",
      "(587, 'Mighty Doll', 17.18)\n",
      "(588, 'Magic Robot', 13.61)\n",
      "(589, 'Wonder Car', 15.94)\n",
      "(590, 'Magic Dragon', 6.53)\n",
      "(591, 'Wonder Train', 14.79)\n",
      "(592, 'Magic Robot', 8.36)\n",
      "(593, 'Happy Bear', 7.65)\n",
      "(594, 'Mighty Train', 5.06)\n",
      "(595, 'Crazy Robot', 15.51)\n",
      "(596, 'Wonder Car', 12.83)\n",
      "(597, 'Super Train', 16.5)\n",
      "(598, 'Wonder Train', 13.31)\n",
      "(599, 'Crazy Bear', 7.97)\n",
      "(600, 'Super Doll', 18.48)\n",
      "(601, 'Happy Car', 7.2)\n",
      "(602, 'Magic Dragon', 18.71)\n",
      "(603, 'Magic Doll', 18.51)\n",
      "(604, 'Magic Robot', 15.66)\n",
      "(605, 'Crazy Bear', 13.86)\n",
      "(606, 'Mighty Train', 5.58)\n",
      "(607, 'Magic Dragon', 16.89)\n",
      "(608, 'Mighty Train', 16.74)\n",
      "(609, 'Wonder Train', 7.48)\n",
      "(610, 'Crazy Car', 9.49)\n",
      "(611, 'Crazy Bear', 15.89)\n",
      "(612, 'Mighty Dragon', 14.3)\n",
      "(613, 'Super Car', 14.19)\n",
      "(614, 'Happy Doll', 8.21)\n",
      "(615, 'Wonder Doll', 15.01)\n",
      "(616, 'Super Car', 13.57)\n",
      "(617, 'Crazy Bear', 19.12)\n",
      "(618, 'Happy Train', 6.58)\n",
      "(619, 'Magic Bear', 19.28)\n",
      "(620, 'Crazy Car', 10.83)\n",
      "(621, 'Super Bear', 16.49)\n",
      "(622, 'Magic Robot', 14.7)\n",
      "(623, 'Crazy Train', 10.09)\n",
      "(624, 'Super Dragon', 15.8)\n",
      "(625, 'Happy Bear', 14.66)\n",
      "(626, 'Happy Dragon', 16.83)\n",
      "(627, 'Wonder Bear', 17.46)\n",
      "(628, 'Super Doll', 12.03)\n",
      "(629, 'Mighty Robot', 18.41)\n",
      "(630, 'Mighty Dragon', 14.14)\n",
      "(631, 'Magic Dragon', 15.98)\n",
      "(632, 'Happy Car', 13.02)\n",
      "(633, 'Wonder Robot', 8.1)\n",
      "(634, 'Wonder Doll', 18.22)\n",
      "(635, 'Wonder Robot', 7.61)\n",
      "(636, 'Happy Car', 17.88)\n",
      "(637, 'Crazy Bear', 14.72)\n",
      "(638, 'Happy Doll', 13.44)\n",
      "(639, 'Crazy Dragon', 18.54)\n",
      "(640, 'Wonder Bear', 5.06)\n",
      "(641, 'Happy Doll', 15.28)\n",
      "(642, 'Super Train', 17.9)\n",
      "(643, 'Crazy Doll', 16.26)\n",
      "(644, 'Super Dragon', 14.76)\n",
      "(645, 'Happy Dragon', 10.35)\n",
      "(646, 'Mighty Car', 17.49)\n",
      "(647, 'Crazy Train', 19.69)\n",
      "(648, 'Mighty Dragon', 15.97)\n",
      "(649, 'Crazy Car', 7.74)\n",
      "(650, 'Super Bear', 14.85)\n",
      "(651, 'Super Robot', 5.59)\n",
      "(652, 'Magic Bear', 17.09)\n",
      "(653, 'Happy Doll', 6.72)\n",
      "(654, 'Super Doll', 8.03)\n",
      "(655, 'Magic Car', 19.61)\n",
      "(656, 'Crazy Bear', 10.99)\n",
      "(657, 'Wonder Robot', 6.7)\n",
      "(658, 'Super Bear', 19.36)\n",
      "(659, 'Super Doll', 6.34)\n",
      "(660, 'Magic Car', 13.54)\n",
      "(661, 'Crazy Robot', 5.32)\n",
      "(662, 'Super Doll', 12.2)\n",
      "(663, 'Magic Bear', 11.18)\n",
      "(664, 'Magic Doll', 5.0)\n",
      "(665, 'Happy Bear', 12.56)\n",
      "(666, 'Happy Bear', 17.21)\n",
      "(667, 'Mighty Car', 16.39)\n",
      "(668, 'Happy Robot', 17.7)\n",
      "(669, 'Crazy Dragon', 18.87)\n",
      "(670, 'Mighty Dragon', 14.32)\n",
      "(671, 'Mighty Dragon', 12.16)\n",
      "(672, 'Mighty Dragon', 18.86)\n",
      "(673, 'Wonder Car', 15.73)\n",
      "(674, 'Magic Car', 8.48)\n",
      "(675, 'Crazy Dragon', 5.25)\n",
      "(676, 'Magic Robot', 8.36)\n",
      "(677, 'Magic Train', 7.68)\n",
      "(678, 'Wonder Bear', 11.74)\n",
      "(679, 'Super Bear', 8.1)\n",
      "(680, 'Super Car', 16.4)\n",
      "(681, 'Happy Dragon', 11.18)\n",
      "(682, 'Mighty Robot', 17.05)\n",
      "(683, 'Mighty Train', 9.57)\n",
      "(684, 'Mighty Train', 5.68)\n",
      "(685, 'Wonder Bear', 15.21)\n",
      "(686, 'Crazy Bear', 11.74)\n",
      "(687, 'Mighty Dragon', 16.14)\n",
      "(688, 'Mighty Dragon', 8.33)\n",
      "(689, 'Crazy Car', 5.8)\n",
      "(690, 'Crazy Dragon', 16.13)\n",
      "(691, 'Mighty Robot', 10.94)\n",
      "(692, 'Crazy Doll', 18.48)\n",
      "(693, 'Mighty Bear', 14.67)\n",
      "(694, 'Wonder Dragon', 5.24)\n",
      "(695, 'Super Robot', 6.23)\n",
      "(696, 'Magic Train', 13.92)\n",
      "(697, 'Crazy Doll', 7.5)\n",
      "(698, 'Super Train', 12.65)\n",
      "(699, 'Magic Robot', 15.35)\n",
      "(700, 'Crazy Car', 5.07)\n",
      "(701, 'Crazy Train', 16.98)\n",
      "(702, 'Super Robot', 7.08)\n",
      "(703, 'Crazy Train', 7.06)\n",
      "(704, 'Crazy Dragon', 19.36)\n",
      "(705, 'Wonder Doll', 11.16)\n",
      "(706, 'Magic Bear', 19.47)\n",
      "(707, 'Magic Train', 7.63)\n",
      "(708, 'Happy Robot', 13.41)\n",
      "(709, 'Mighty Robot', 13.28)\n",
      "(710, 'Magic Doll', 18.52)\n",
      "(711, 'Super Train', 8.66)\n",
      "(712, 'Mighty Doll', 10.22)\n",
      "(713, 'Happy Doll', 9.73)\n",
      "(714, 'Magic Robot', 7.62)\n",
      "(715, 'Super Car', 10.17)\n",
      "(716, 'Super Train', 13.88)\n",
      "(717, 'Super Car', 18.17)\n",
      "(718, 'Super Car', 7.91)\n",
      "(719, 'Happy Robot', 6.53)\n",
      "(720, 'Happy Car', 17.52)\n",
      "(721, 'Happy Doll', 7.56)\n",
      "(722, 'Crazy Bear', 18.4)\n",
      "(723, 'Wonder Train', 15.91)\n",
      "(724, 'Happy Doll', 14.49)\n",
      "(725, 'Wonder Robot', 19.94)\n",
      "(726, 'Wonder Car', 17.58)\n",
      "(727, 'Super Doll', 5.07)\n",
      "(728, 'Super Doll', 5.56)\n",
      "(729, 'Wonder Robot', 9.16)\n",
      "(730, 'Magic Robot', 16.38)\n",
      "(731, 'Magic Train', 17.97)\n",
      "(732, 'Magic Bear', 7.47)\n",
      "(733, 'Wonder Robot', 12.63)\n",
      "(734, 'Magic Bear', 12.88)\n",
      "(735, 'Mighty Robot', 10.69)\n",
      "(736, 'Mighty Robot', 13.3)\n",
      "(737, 'Magic Doll', 11.07)\n",
      "(738, 'Crazy Dragon', 8.31)\n",
      "(739, 'Magic Doll', 13.37)\n",
      "(740, 'Crazy Car', 7.87)\n",
      "(741, 'Happy Robot', 5.73)\n",
      "(742, 'Happy Robot', 10.32)\n",
      "(743, 'Magic Bear', 11.38)\n",
      "(744, 'Wonder Dragon', 13.24)\n",
      "(745, 'Crazy Doll', 8.03)\n",
      "(746, 'Super Train', 11.72)\n",
      "(747, 'Magic Robot', 18.67)\n",
      "(748, 'Super Dragon', 15.12)\n",
      "(749, 'Mighty Dragon', 7.2)\n",
      "(750, 'Happy Train', 6.67)\n",
      "(751, 'Mighty Robot', 17.53)\n",
      "(752, 'Mighty Doll', 16.83)\n",
      "(753, 'Mighty Bear', 13.33)\n",
      "(754, 'Happy Robot', 14.15)\n",
      "(755, 'Magic Doll', 5.75)\n",
      "(756, 'Magic Doll', 17.83)\n",
      "(757, 'Mighty Train', 15.73)\n",
      "(758, 'Mighty Robot', 13.04)\n",
      "(759, 'Magic Train', 11.54)\n",
      "(760, 'Mighty Robot', 12.92)\n",
      "(761, 'Crazy Doll', 6.24)\n",
      "(762, 'Crazy Robot', 8.75)\n",
      "(763, 'Magic Robot', 8.01)\n",
      "(764, 'Super Dragon', 7.5)\n",
      "(765, 'Magic Train', 7.46)\n",
      "(766, 'Super Train', 14.31)\n",
      "(767, 'Magic Bear', 11.7)\n",
      "(768, 'Crazy Bear', 12.75)\n",
      "(769, 'Happy Bear', 7.6)\n",
      "(770, 'Mighty Robot', 14.49)\n",
      "(771, 'Magic Train', 10.71)\n",
      "(772, 'Crazy Car', 14.12)\n",
      "(773, 'Happy Train', 9.35)\n",
      "(774, 'Happy Train', 15.33)\n",
      "(775, 'Super Train', 6.3)\n",
      "(776, 'Magic Doll', 14.43)\n",
      "(777, 'Crazy Bear', 5.37)\n",
      "(778, 'Mighty Dragon', 7.8)\n",
      "(779, 'Crazy Dragon', 19.29)\n",
      "(780, 'Mighty Robot', 13.82)\n",
      "(781, 'Magic Bear', 18.74)\n",
      "(782, 'Happy Car', 5.47)\n",
      "(783, 'Happy Train', 13.03)\n",
      "(784, 'Super Robot', 15.26)\n",
      "(785, 'Crazy Car', 6.97)\n",
      "(786, 'Happy Dragon', 10.67)\n",
      "(787, 'Mighty Doll', 6.75)\n",
      "(788, 'Wonder Bear', 15.57)\n",
      "(789, 'Magic Robot', 16.76)\n",
      "(790, 'Happy Robot', 10.07)\n",
      "(791, 'Crazy Doll', 14.56)\n",
      "(792, 'Crazy Dragon', 7.41)\n",
      "(793, 'Mighty Train', 8.82)\n",
      "(794, 'Crazy Robot', 12.69)\n",
      "(795, 'Magic Doll', 12.78)\n",
      "(796, 'Magic Doll', 17.02)\n",
      "(797, 'Happy Doll', 14.29)\n",
      "(798, 'Super Doll', 12.83)\n",
      "(799, 'Happy Doll', 10.27)\n",
      "(800, 'Super Car', 6.48)\n",
      "(801, 'Happy Car', 18.7)\n",
      "(802, 'Super Car', 5.9)\n",
      "(803, 'Happy Car', 16.08)\n",
      "(804, 'Crazy Bear', 18.8)\n",
      "(805, 'Wonder Bear', 13.06)\n",
      "(806, 'Wonder Bear', 18.58)\n",
      "(807, 'Crazy Car', 10.91)\n",
      "(808, 'Happy Train', 5.42)\n",
      "(809, 'Crazy Bear', 12.36)\n",
      "(810, 'Magic Car', 11.7)\n",
      "(811, 'Magic Car', 10.48)\n",
      "(812, 'Super Dragon', 14.06)\n",
      "(813, 'Happy Car', 6.67)\n",
      "(814, 'Super Robot', 10.4)\n",
      "(815, 'Crazy Dragon', 19.96)\n",
      "(816, 'Wonder Robot', 9.84)\n",
      "(817, 'Magic Train', 15.88)\n",
      "(818, 'Super Robot', 8.78)\n",
      "(819, 'Happy Dragon', 13.66)\n",
      "(820, 'Crazy Bear', 15.82)\n",
      "(821, 'Super Robot', 12.29)\n",
      "(822, 'Super Robot', 7.96)\n",
      "(823, 'Super Bear', 6.2)\n",
      "(824, 'Magic Dragon', 12.06)\n",
      "(825, 'Happy Dragon', 14.39)\n",
      "(826, 'Crazy Car', 12.37)\n",
      "(827, 'Mighty Doll', 14.28)\n",
      "(828, 'Super Robot', 8.2)\n",
      "(829, 'Wonder Train', 13.22)\n",
      "(830, 'Happy Bear', 17.78)\n",
      "(831, 'Crazy Car', 10.92)\n",
      "(832, 'Happy Train', 13.31)\n",
      "(833, 'Magic Dragon', 17.32)\n",
      "(834, 'Magic Robot', 16.85)\n",
      "(835, 'Magic Car', 12.08)\n",
      "(836, 'Super Doll', 19.51)\n",
      "(837, 'Crazy Dragon', 13.19)\n",
      "(838, 'Mighty Robot', 11.13)\n",
      "(839, 'Magic Bear', 5.63)\n",
      "(840, 'Happy Car', 7.24)\n",
      "(841, 'Mighty Car', 14.46)\n",
      "(842, 'Super Doll', 8.56)\n",
      "(843, 'Super Bear', 5.35)\n",
      "(844, 'Super Robot', 7.9)\n",
      "(845, 'Wonder Train', 19.34)\n",
      "(846, 'Happy Robot', 9.17)\n",
      "(847, 'Crazy Bear', 17.44)\n",
      "(848, 'Happy Doll', 11.74)\n",
      "(849, 'Crazy Train', 19.68)\n",
      "(850, 'Happy Doll', 5.68)\n",
      "(851, 'Super Dragon', 10.41)\n",
      "(852, 'Mighty Train', 18.7)\n",
      "(853, 'Mighty Dragon', 14.73)\n",
      "(854, 'Super Doll', 6.2)\n",
      "(855, 'Happy Dragon', 18.6)\n",
      "(856, 'Mighty Doll', 10.56)\n",
      "(857, 'Crazy Dragon', 9.4)\n",
      "(858, 'Crazy Doll', 17.51)\n",
      "(859, 'Magic Train', 15.86)\n",
      "(860, 'Magic Car', 6.66)\n",
      "(861, 'Happy Bear', 15.73)\n",
      "(862, 'Magic Train', 15.37)\n",
      "(863, 'Mighty Train', 12.06)\n",
      "(864, 'Mighty Car', 6.53)\n",
      "(865, 'Super Robot', 12.82)\n",
      "(866, 'Super Robot', 6.96)\n",
      "(867, 'Mighty Car', 11.4)\n",
      "(868, 'Crazy Bear', 17.39)\n",
      "(869, 'Super Bear', 15.03)\n",
      "(870, 'Happy Dragon', 16.09)\n",
      "(871, 'Magic Robot', 11.19)\n",
      "(872, 'Super Doll', 8.9)\n",
      "(873, 'Super Robot', 5.17)\n",
      "(874, 'Crazy Robot', 9.02)\n",
      "(875, 'Magic Dragon', 10.28)\n",
      "(876, 'Wonder Car', 6.05)\n",
      "(877, 'Magic Dragon', 15.51)\n",
      "(878, 'Magic Doll', 12.45)\n",
      "(879, 'Mighty Bear', 14.11)\n",
      "(880, 'Wonder Bear', 18.24)\n",
      "(881, 'Happy Train', 6.71)\n",
      "(882, 'Super Doll', 18.27)\n",
      "(883, 'Happy Doll', 14.24)\n",
      "(884, 'Wonder Doll', 19.61)\n",
      "(885, 'Mighty Train', 17.74)\n",
      "(886, 'Wonder Car', 18.97)\n",
      "(887, 'Mighty Train', 9.72)\n",
      "(888, 'Super Robot', 17.48)\n",
      "(889, 'Happy Robot', 18.89)\n",
      "(890, 'Mighty Dragon', 18.76)\n",
      "(891, 'Mighty Dragon', 5.91)\n",
      "(892, 'Wonder Train', 15.79)\n",
      "(893, 'Magic Robot', 8.06)\n",
      "(894, 'Wonder Doll', 19.35)\n",
      "(895, 'Magic Dragon', 7.74)\n",
      "(896, 'Crazy Car', 17.56)\n",
      "(897, 'Happy Bear', 6.18)\n",
      "(898, 'Magic Car', 18.18)\n",
      "(899, 'Crazy Train', 5.53)\n",
      "(900, 'Super Robot', 6.67)\n",
      "(901, 'Super Robot', 16.23)\n",
      "(902, 'Super Dragon', 17.68)\n",
      "(903, 'Crazy Train', 10.81)\n",
      "(904, 'Wonder Robot', 15.82)\n",
      "(905, 'Super Robot', 16.8)\n",
      "(906, 'Super Train', 7.28)\n",
      "(907, 'Super Bear', 5.71)\n",
      "(908, 'Magic Robot', 18.51)\n",
      "(909, 'Magic Car', 13.87)\n",
      "(910, 'Super Train', 9.7)\n",
      "(911, 'Magic Robot', 7.53)\n",
      "(912, 'Mighty Robot', 15.69)\n",
      "(913, 'Super Doll', 5.27)\n",
      "(914, 'Super Robot', 14.81)\n",
      "(915, 'Magic Robot', 11.49)\n",
      "(916, 'Super Bear', 12.11)\n",
      "(917, 'Mighty Bear', 8.82)\n",
      "(918, 'Magic Train', 7.67)\n",
      "(919, 'Crazy Doll', 18.4)\n",
      "(920, 'Mighty Car', 9.05)\n",
      "(921, 'Happy Robot', 10.41)\n",
      "(922, 'Magic Doll', 6.97)\n",
      "(923, 'Wonder Doll', 7.48)\n",
      "(924, 'Super Train', 15.2)\n",
      "(925, 'Mighty Doll', 10.96)\n",
      "(926, 'Super Doll', 18.47)\n",
      "(927, 'Happy Bear', 9.78)\n",
      "(928, 'Happy Bear', 13.03)\n",
      "(929, 'Wonder Bear', 18.08)\n",
      "(930, 'Wonder Dragon', 16.74)\n",
      "(931, 'Mighty Robot', 17.86)\n",
      "(932, 'Wonder Dragon', 17.54)\n",
      "(933, 'Magic Car', 16.0)\n",
      "(934, 'Crazy Car', 11.56)\n",
      "(935, 'Wonder Doll', 10.07)\n",
      "(936, 'Mighty Bear', 14.42)\n",
      "(937, 'Magic Bear', 17.96)\n",
      "(938, 'Wonder Car', 17.19)\n",
      "(939, 'Wonder Bear', 13.85)\n",
      "(940, 'Magic Doll', 18.3)\n",
      "(941, 'Wonder Dragon', 13.76)\n",
      "(942, 'Super Dragon', 16.75)\n",
      "(943, 'Happy Robot', 19.42)\n",
      "(944, 'Crazy Robot', 12.62)\n",
      "(945, 'Crazy Robot', 16.47)\n",
      "(946, 'Super Robot', 18.13)\n",
      "(947, 'Crazy Bear', 19.88)\n",
      "(948, 'Mighty Car', 11.23)\n",
      "(949, 'Mighty Train', 18.49)\n",
      "(950, 'Mighty Robot', 11.27)\n",
      "(951, 'Happy Car', 11.42)\n",
      "(952, 'Super Car', 19.25)\n",
      "(953, 'Crazy Robot', 16.36)\n",
      "(954, 'Crazy Car', 7.05)\n",
      "(955, 'Magic Bear', 17.79)\n",
      "(956, 'Mighty Dragon', 12.79)\n",
      "(957, 'Mighty Bear', 7.38)\n",
      "(958, 'Happy Train', 6.43)\n",
      "(959, 'Mighty Car', 11.33)\n",
      "(960, 'Magic Car', 15.36)\n",
      "(961, 'Magic Robot', 11.17)\n",
      "(962, 'Happy Bear', 9.43)\n",
      "(963, 'Super Bear', 12.54)\n",
      "(964, 'Super Doll', 17.08)\n",
      "(965, 'Happy Bear', 16.5)\n",
      "(966, 'Super Train', 14.5)\n",
      "(967, 'Mighty Train', 16.07)\n",
      "(968, 'Mighty Bear', 14.01)\n",
      "(969, 'Super Dragon', 14.02)\n",
      "(970, 'Crazy Robot', 17.42)\n",
      "(971, 'Crazy Doll', 12.12)\n",
      "(972, 'Super Train', 17.54)\n",
      "(973, 'Super Dragon', 13.3)\n",
      "(974, 'Wonder Car', 13.54)\n",
      "(975, 'Magic Train', 8.72)\n",
      "(976, 'Wonder Dragon', 15.27)\n",
      "(977, 'Happy Car', 10.09)\n",
      "(978, 'Crazy Doll', 17.46)\n",
      "(979, 'Mighty Car', 10.04)\n",
      "(980, 'Super Car', 6.87)\n",
      "(981, 'Super Dragon', 5.92)\n",
      "(982, 'Happy Dragon', 5.3)\n",
      "(983, 'Crazy Robot', 17.98)\n",
      "(984, 'Wonder Train', 19.07)\n",
      "(985, 'Happy Robot', 6.03)\n",
      "(986, 'Super Robot', 16.45)\n",
      "(987, 'Crazy Car', 15.27)\n",
      "(988, 'Mighty Robot', 6.8)\n",
      "(989, 'Crazy Robot', 12.58)\n",
      "(990, 'Happy Train', 5.16)\n",
      "(991, 'Crazy Car', 13.54)\n",
      "(992, 'Super Car', 9.08)\n",
      "(993, 'Mighty Bear', 6.16)\n",
      "(994, 'Wonder Doll', 9.16)\n",
      "(995, 'Wonder Bear', 9.76)\n",
      "(996, 'Super Robot', 11.43)\n",
      "(997, 'Wonder Car', 11.37)\n",
      "(998, 'Magic Doll', 6.49)\n",
      "(999, 'Happy Bear', 7.8)\n",
      "(1000, 'Crazy Robot', 18.17)\n",
      "(1001, 'Mighty Robot', 8.77)\n",
      "(1002, 'Magic Robot', 14.23)\n",
      "(1003, 'Wonder Car', 14.24)\n",
      "(1004, 'Wonder Train', 18.76)\n",
      "(1005, 'Mighty Bear', 7.46)\n",
      "(1006, 'Crazy Car', 13.17)\n",
      "(1007, 'Wonder Bear', 13.71)\n",
      "(1008, 'Magic Dragon', 18.83)\n",
      "(1009, 'Wonder Bear', 18.73)\n",
      "(1010, 'Super Doll', 18.94)\n",
      "(1011, 'Wonder Robot', 10.81)\n",
      "(1012, 'Magic Dragon', 8.08)\n",
      "(1013, 'Magic Bear', 13.93)\n",
      "(1014, 'Super Dragon', 17.43)\n",
      "(1015, 'Magic Car', 7.59)\n",
      "(1016, 'Super Robot', 6.27)\n",
      "(1017, 'Magic Bear', 6.93)\n",
      "(1018, 'Super Bear', 10.31)\n",
      "(1019, 'Crazy Bear', 10.91)\n",
      "(1020, 'Happy Train', 9.67)\n",
      "(1021, 'Crazy Dragon', 16.99)\n",
      "(1022, 'Mighty Car', 15.92)\n",
      "(1023, 'Happy Dragon', 17.09)\n",
      "(1024, 'Magic Bear', 18.88)\n",
      "(1025, 'Crazy Train', 10.31)\n",
      "(1026, 'Mighty Dragon', 18.74)\n",
      "(1027, 'Super Robot', 5.42)\n",
      "(1028, 'Happy Train', 12.2)\n",
      "(1029, 'Magic Robot', 15.93)\n",
      "(1030, 'Wonder Doll', 8.82)\n",
      "(1031, 'Magic Car', 13.72)\n",
      "(1032, 'Crazy Car', 12.84)\n",
      "(1033, 'Super Doll', 8.36)\n",
      "(1034, 'Mighty Car', 14.94)\n",
      "(1035, 'Wonder Bear', 19.13)\n",
      "(1036, 'Super Robot', 12.66)\n",
      "(1037, 'Magic Train', 16.17)\n",
      "(1038, 'Wonder Doll', 9.96)\n",
      "(1039, 'Magic Bear', 17.89)\n",
      "(1040, 'Happy Doll', 12.68)\n",
      "(1041, 'Wonder Train', 15.09)\n",
      "(1042, 'Super Bear', 9.74)\n",
      "(1043, 'Crazy Bear', 17.13)\n",
      "(1044, 'Mighty Robot', 14.39)\n",
      "(1045, 'Happy Robot', 9.93)\n",
      "(1046, 'Wonder Dragon', 6.76)\n",
      "(1047, 'Happy Bear', 12.68)\n",
      "(1048, 'Mighty Dragon', 13.38)\n",
      "(1049, 'Happy Bear', 7.28)\n",
      "(1050, 'Mighty Train', 7.47)\n",
      "(1051, 'Super Doll', 16.48)\n",
      "(1052, 'Happy Train', 7.8)\n",
      "(1053, 'Happy Doll', 5.64)\n",
      "(1054, 'Crazy Doll', 10.31)\n",
      "(1055, 'Magic Dragon', 19.95)\n",
      "(1056, 'Magic Dragon', 6.26)\n",
      "(1057, 'Super Bear', 16.88)\n",
      "(1058, 'Crazy Train', 7.11)\n",
      "(1059, 'Magic Dragon', 11.98)\n",
      "(1060, 'Mighty Robot', 15.0)\n",
      "(1061, 'Crazy Train', 12.14)\n",
      "(1062, 'Super Doll', 9.96)\n",
      "(1063, 'Wonder Bear', 15.48)\n",
      "(1064, 'Crazy Robot', 15.74)\n",
      "(1065, 'Mighty Bear', 7.93)\n",
      "(1066, 'Magic Doll', 10.72)\n",
      "(1067, 'Wonder Train', 15.84)\n",
      "(1068, 'Crazy Bear', 18.09)\n",
      "(1069, 'Magic Robot', 13.74)\n",
      "(1070, 'Wonder Bear', 9.46)\n",
      "(1071, 'Happy Train', 17.08)\n",
      "(1072, 'Mighty Bear', 11.76)\n",
      "(1073, 'Super Robot', 8.49)\n",
      "(1074, 'Magic Car', 10.92)\n",
      "(1075, 'Super Bear', 10.8)\n",
      "(1076, 'Super Robot', 10.77)\n",
      "(1077, 'Crazy Doll', 5.76)\n",
      "(1078, 'Wonder Doll', 12.49)\n",
      "(1079, 'Super Robot', 11.31)\n",
      "(1080, 'Magic Train', 6.94)\n",
      "(1081, 'Wonder Train', 8.79)\n",
      "(1082, 'Magic Dragon', 12.6)\n",
      "(1083, 'Super Robot', 9.62)\n",
      "(1084, 'Wonder Train', 12.42)\n",
      "(1085, 'Happy Bear', 10.0)\n",
      "(1086, 'Super Train', 9.19)\n",
      "(1087, 'Super Bear', 7.68)\n",
      "(1088, 'Wonder Dragon', 11.6)\n",
      "(1089, 'Super Dragon', 10.7)\n",
      "(1090, 'Mighty Bear', 14.44)\n",
      "(1091, 'Super Dragon', 5.07)\n",
      "(1092, 'Wonder Train', 15.42)\n",
      "(1093, 'Super Car', 17.94)\n",
      "(1094, 'Magic Train', 17.85)\n",
      "(1095, 'Super Doll', 15.27)\n",
      "(1096, 'Wonder Robot', 12.39)\n",
      "(1097, 'Crazy Robot', 13.98)\n",
      "(1098, 'Magic Car', 11.24)\n",
      "(1099, 'Happy Robot', 15.08)\n",
      "(1100, 'Wonder Dragon', 13.63)\n"
     ]
    }
   ],
   "source": [
    "from utils import create_random_database\n",
    "create_random_database()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "2c24db79-d9bd-4850-861b-b246938e45a6",
   "metadata": {
    "height": 30
   },
   "outputs": [],
   "source": [
    "question = \"What is the most expensive item we currently sell?\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "f0b9d650-daba-4374-a6d1-5d8f0a382a8f",
   "metadata": {
    "height": 455
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "LLM's function call: execute_sql(sql_code='SELECT name, price FROM toys ORDER BY price DESC LIMIT 1')\n"
     ]
    }
   ],
   "source": [
    "from utils import execute_sql, query_raven\n",
    "\n",
    "schema = \\\n",
    "\"\"\"\n",
    "CREATE TABLE IF NOT EXISTS toys (\n",
    "    id INTEGER PRIMARY KEY,\n",
    "    name TEXT,\n",
    "    price REAL\n",
    ");\n",
    "\"\"\"\n",
    "\n",
    "raven_prompt = \\\n",
    "f'''\n",
    "Function:\n",
    "def execute_sql(sql_code : str):\n",
    "  \"\"\"\n",
    "  Runs sql code for a company internal database\n",
    "  \"\"\"\n",
    "\n",
    "Schema: {schema}\n",
    "User Query: {question}\n",
    "'''\n",
    "\n",
    "output = query_raven(raven_prompt)\n",
    "print (f\"LLM's function call: {output}\")\n",
    "database_result = eval(output)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "34109001-b30e-485a-a917-8639f5c6f241",
   "metadata": {
    "height": 217
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The most expensive item we currently sell is the Crazy Dragon, which costs 19.96.\n"
     ]
    }
   ],
   "source": [
    "full_prompt = \\\n",
    "f\"\"\"\n",
    "<s> [INST]\n",
    "{database_result}\n",
    "\n",
    "Use the information above to answer the following question concisely.\n",
    "\n",
    "Question:\n",
    "{question} [/INST]\n",
    "\"\"\"\n",
    "grounded_response = query_raven(full_prompt)\n",
    "print (grounded_response)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7ace25e8-4526-4b10-97e4-4829e6a561fa",
   "metadata": {},
   "source": [
    "### Safer Interactions With Databases\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "554765e6-dcf4-4c79-b23e-3f78f0a2cf41",
   "metadata": {
    "height": 166
   },
   "outputs": [],
   "source": [
    "import sqlite3\n",
    "import random\n",
    "\n",
    "# Internal database name setting\n",
    "DB_NAME = 'toy_database.db'\n",
    "\n",
    "# Connect to the database\n",
    "def connect_db():\n",
    "    return sqlite3.connect(DB_NAME)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "58cfcc25-6324-46b4-9b69-dcce24106f66",
   "metadata": {
    "height": 115
   },
   "outputs": [],
   "source": [
    "# List all toys\n",
    "def list_all_toys():\n",
    "    with connect_db() as conn:\n",
    "        cursor = conn.execute('SELECT * FROM toys')\n",
    "        return cursor.fetchall()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "a0772168-ef5e-41bb-9181-0c38f896055d",
   "metadata": {
    "height": 132
   },
   "outputs": [],
   "source": [
    "# Find toy by name prefix\n",
    "def find_toy_by_prefix(prefix):\n",
    "    with connect_db() as conn:\n",
    "        query = 'SELECT * FROM toys WHERE name LIKE ?'\n",
    "        cursor = conn.execute(query, (prefix + '%',))\n",
    "        return cursor.fetchall()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "7cf610e1-6384-405c-a81c-00f1f8443008",
   "metadata": {
    "height": 115
   },
   "outputs": [],
   "source": [
    "# Find toys in a price range\n",
    "def find_toys_in_price_range(low_price, high_price):\n",
    "    with connect_db() as conn:\n",
    "        query = 'SELECT * FROM toys WHERE price BETWEEN ? AND ?'\n",
    "        cursor = conn.execute(query, (low_price, high_price))\n",
    "        return cursor.fetchall()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "76e38d51-88c1-45b3-aa92-99df03fa7b49",
   "metadata": {
    "height": 115
   },
   "outputs": [],
   "source": [
    "# Get a random selection of toys\n",
    "def get_random_toys(count=5):\n",
    "    with connect_db() as conn:\n",
    "        cursor = conn.execute('SELECT * FROM toys')\n",
    "        all_toys = cursor.fetchall()\n",
    "        return random.sample(all_toys, min(count, len(all_toys)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "92a358df-c160-45ca-9b3e-e7c4602648c4",
   "metadata": {
    "height": 115
   },
   "outputs": [],
   "source": [
    "# Function to get the most expensive toy\n",
    "def get_most_expensive_toy(count=1):\n",
    "    with connect_db() as conn:\n",
    "        cursor = conn.execute(f'SELECT * FROM toys ORDER BY price DESC LIMIT {count}')\n",
    "        return cursor.fetchone()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "a625c123-0bb6-423d-b690-4851f6f70a80",
   "metadata": {
    "height": 98
   },
   "outputs": [],
   "source": [
    "# Function to get the cheapest toy\n",
    "def get_cheapest_toy(count=1):\n",
    "    with connect_db() as conn:\n",
    "        cursor = conn.execute('SELECT * FROM toys ORDER BY price ASC LIMIT {count}')\n",
    "        return cursor.fetchone()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "b507eb02-6779-4742-b0b2-48fb2fcaba1a",
   "metadata": {
    "height": 1050
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "get_most_expensive_toy(count=1)\n"
     ]
    }
   ],
   "source": [
    "raven_prompt = \\\n",
    "f'''\n",
    "Function:\n",
    "def list_all_toys():\n",
    "    \"\"\"\n",
    "    Retrieves a list of all toys from the database. This function does not take any parameters.\n",
    "    Returns: A list of tuples, where each tuple represents a toy with all its attributes (id, name, price).\n",
    "    \"\"\"\n",
    "\n",
    "Function:\n",
    "def find_toy_by_prefix(prefix):\n",
    "    \"\"\"\n",
    "    Searches for and retrieves toys whose names start with a specified prefix.\n",
    "    Parameters:\n",
    "    - prefix (str): The prefix to search for in toy names.\n",
    "    Returns: A list of tuples, where each tuple represents a toy that matches the prefix criteria.\n",
    "    \"\"\"\n",
    "\n",
    "Function:\n",
    "def find_toys_in_price_range(low_price, high_price):\n",
    "    \"\"\"\n",
    "    Finds and returns toys within a specified price range.\n",
    "    Parameters:\n",
    "    - low_price (float): The lower bound of the price range.\n",
    "    - high_price (float): The upper bound of the price range.\n",
    "    Returns: A list of tuples, each representing a toy whose price falls within the specified range.\n",
    "    \"\"\"\n",
    "\n",
    "Function:\n",
    "def get_random_toys():\n",
    "    \"\"\"\n",
    "    Selects and returns a random set of toys from the database, simulating a \"featured toys\" list.\n",
    "\n",
    "    Returns: A list of tuples, each representing a randomly selected toy. The number of toys returned is up to the specified count.\n",
    "    \"\"\"\n",
    "\n",
    "Function:\n",
    "def get_most_expensive_toy(count : int):\n",
    "    \"\"\"\n",
    "    Retrieves the most expensive toy from the database.\n",
    "    This function does not take any parameters.\n",
    "\n",
    "    Returns: A tuple representing the most expensive toy, including its id, name, and price.\n",
    "    \"\"\"\n",
    "\n",
    "Function:\n",
    "def get_cheapest_toy(count : int):\n",
    "    \"\"\"\n",
    "    Finds and retrieves the cheapest toy in the database.\n",
    "    This function does not take any parameters.\n",
    "\n",
    "    Returns: A tuple representing the cheapest toy, including its id, name, and price.\n",
    "    \"\"\"\n",
    "\n",
    "User Query: {question}<human_end>\n",
    "\n",
    "'''\n",
    "\n",
    "output = query_raven(raven_prompt)\n",
    "print (output)\n",
    "results = eval(output)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "4cda6a9e-454e-47af-9f01-cbd872ce1815",
   "metadata": {
    "height": 217
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The most expensive item we currently sell is the Crazy Dragon, which costs 19.96.\n"
     ]
    }
   ],
   "source": [
    "full_prompt = \\\n",
    "f\"\"\"\n",
    "<s> [INST]\n",
    "{database_result}\n",
    "\n",
    "Use the information above to answer the following question in a single sentence.\n",
    "\n",
    "Question:\n",
    "{question} [/INST]\n",
    "\"\"\"\n",
    "grounded_response = query_raven(full_prompt)\n",
    "print (grounded_response)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1267ca30-e928-4655-af6b-66aabcf9e639",
   "metadata": {
    "height": 30
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
